<template>
	<view class="main-box">
		<view v-if="orderList.length > 0" class="list-box">
			<view class="item" v-for="(item,index) in orderList" :key="index">
				<view class="item-title">
					<span class="title">{{item.name}}</span>
					<span class="money">￥{{item.money}}</span>
				</view>
				<view class="item-text">
					<text>下单手机号</text>
					<text>{{item.mobile}}</text>
				</view>
				<view class="item-text">
					<text>订单号</text>
					<text>{{item.orderno}}</text>
				</view>
				<view class="item-text">
					<text>订单创建时间</text>
					<text>{{item.createtime}}</text>
				</view>
				<view class="item-text">
					<text>成功支付时间</text>
					<text>{{item.updatetime}}</text>
				</view>
				<view class="item-text">
					<text>订单状态</text>
					<text class="money">{{item.status}}</text>
				</view>
			</view>
		</view>
		<view v-if="isShowNoData" class="no-data">
			<image class="no-data-img" mode="widthFix"
				src="https://qiming-1308147483.cos.ap-chengdu.myqcloud.com/doc/heijinka/tongyong/order_list/order-data.png">
			</image>
		</view>
	</view>
</template>

<script>
	import userApi from '../../api/userApi';
	import orderApi from "@/api/orderApi.js"
	import dateUtil from "@/utils/dateUtil.js"

	export default {
		data() {
			return {
				orderList: [],
				isShowNoData: false,
			};
		},
		onShow() {
			this.getOrderList()
		},
		methods: {
			getOrderList() {
				orderApi.getOrderList(res => {
					let dataList = res.data;
					dataList.forEach(item => {
						//状态:0=支付失败,1=支付成功,-1=未付款
						switch (parseInt(item.status)) {
							case 0:
								item.status = '支付失败'
								break;
							case 1:
								item.status = '支付成功'
								break;
							case -1:
								item.status = '未付款'
								break;
						}
						if (item.createtime) {
							item.createtime = dateUtil.getDateTimeFormtByTimestamp(item.createtime)
						} else {
							item.createtime = '';
						}
						if (item.updatetime) {
							item.updatetime = dateUtil.getDateTimeFormtByTimestamp(item.updatetime)
						} else {
							item.updatetime = '';
						}
						item.name = '省心黑金卡'
						//购买类型:1=季卡,2=半年卡,3=年卡
						switch (parseInt(item.buyType)) {
							case 1:
								item.name += '(季卡)'
								break;
							case 2:
								item.name += '(半年卡)'
								break;
							case 3:
								item.name += '(年卡)'
								break;
						}
					})
					this.orderList = dataList;
					if (dataList.length == 0) {
						this.isShowNoData = true;
					} else {
						this.isShowNoData = false;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.main-box {
		background-color: #e9e9e9;
		min-height: 100vh;
	}

	.list-box {
		padding-top: 20rpx;

		.item {
			width: 90%;
			margin: 0 auto 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 0 20rpx 20rpx;

			.item-title {
				border-bottom: solid 1rpx #d3d3d3;
				height: 70rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;

				.title {
					font-family: SourceHanSansSC-Regular;
					font-size: 30rpx;
					letter-spacing: 1rpx;
					color: #292929;
				}

				.money {
					font-family: SourceHanSansSC-Medium;
					font-size: 30rpx;
					font-weight: bold;
					letter-spacing: 1rpx;
					color: #b51818;
				}

			}

			.item-text {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 45rpx;
				font-family: SourceHanSansSC-Regular;
				font-size: 22rpx;
				font-weight: bold;
				font-stretch: normal;
				letter-spacing: 1rpx;
				color: #797979;

				.money {
					color: #db4545;
				}
			}
		}
	}

	.no-data {
		position: absolute;
		width: 100%;
		height: 100vh;
		background-color: #1e1e1e;
		display: flex;
		justify-content: center;
		align-items: center;

		.no-data-img {
			width: 80%;
			height: auto;
			display: block;
			margin: -80rpx auto 0;

		}
	}
</style>